package com.jensen.controller;

import com.jensen.model.Blog;
import com.jensen.model.User;
import com.jensen.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by sjj on 2015/10/24 0024.
 */
@Controller
public class MainController {

    // 自动装配
    @Autowired
    private UserRepository userRepository;

    // 首页
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index() {
        int id= (int) (Math.random()*1000);
        User user=new User(id,"Jensen","Huang","123");
        List<Blog> blogs=new ArrayList<Blog>();
        Blog blog=new Blog(id,"Hello","world!");
        blog.setUser(user);
        blogs.add(blog);
        user.setBlogs(blogs);
        this.userRepository.save(user);
        return "index";
    }


}